import { App } from 'vue';
import { registerControlProvider } from '@ibiz-template/runtime';
import { withInstall } from '@ibiz-template/vue3-util';
import { OdooGroupGridControl } from './odoo-group-grid';
import { OdooGroupGridProvider } from './odoo-group-grid.provider';

export const IBizOdooGroupGridControl = withInstall(
  OdooGroupGridControl,
  function (v: App) {
    v.component(OdooGroupGridControl.name!, OdooGroupGridControl);
    registerControlProvider(
      'GRID_RENDER_ODOO_GROUP_GRID',
      () => new OdooGroupGridProvider(),
    );
  },
);

export default {
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
  install(app: App, params: IParams = {}) {
    app.component(OdooGroupGridControl.name!, OdooGroupGridControl);
    if (params.replaceglobal && params.replaceglobal === 'true') {
      registerControlProvider(
        'GRID',
        () => new OdooGroupGridProvider(),
      );
    } else {
      registerControlProvider(
        'GRID_RENDER_ODOO_GROUP_GRID',
        () => new OdooGroupGridProvider(),
      );
    }
  },
};
